#include "ChangePass.h"
#include "MainMenu.h"
#include "ui_ChangePass.h"

#include <QMessageBox>

ChangePass::ChangePass(QRect screenGeometry,QWidget *parent) :
    QDialog(parent),
    ui(new Ui::ChangePass)
{
    ui->setupUi(this);
    this->setGeometry(0,0,screenGeometry.width(),screenGeometry.height());
}

ChangePass::~ChangePass()
{
    delete ui;
}

void ChangePass::on_yes_clicked()
{
    if(this->ui->originalPass->text()!=MainMenu::pass)
    {
        QMessageBox *box=new QMessageBox;
        box->warning(nullptr,"","原密码错误");
        box->exec();
        delete box;
    }
    else if(this->ui->newPass->text()!=this->ui->surePass->text())
    {
        QMessageBox *box=new QMessageBox;
        box->warning(nullptr,"","两次输入的密码不相同");
        box->exec();
        delete box;
    }
    else if(this->ui->newPass->text()!="")
    {
        QString str="7E7E;kind:phone;function:06;phone:%1;pass:%2;newPass:%3;";
        str=str.arg(MainMenu::phone).arg(this->ui->originalPass->text()).arg(this->ui->newPass->text());
        emit this->toServerSend_signals(str);
    }
    else {
        QMessageBox *box=new QMessageBox;
        box->warning(nullptr,"","未输入密码");
        box->exec();
        delete box;
    }
}

void ChangePass::on_no_clicked()
{
    this->hide();
}
